class Solution {//leetcode733——图像渲染
private:
    using PII=pair<int,int>;
    int dx[4]={1,-1,0,0};
    int dy[4]={0,0,1,-1};
public:
    vector<vector<int>> floodFill(vector<vector<int>>& image, int sr, int sc, int color) {
        int m=image.size(),n=image[0].size();
        int aim=image[sr][sc];//需要渲染的目标像素
        if(aim==color) return image;

        priority_queue<PII> q;
        q.push({sr,sc});
        while(!q.empty()){
            auto [x1,y1]=q.top();
            q.pop();
            image[x1][y1]=color;
            for(int i=0;i<4;i++){
                int x=x1+dx[i];
                int y=y1+dy[i];
                if(x>=0&&x<m&&y>=0&&y<n&&image[x][y]==aim)
                    q.push({x,y});
            }
        }
        return image;
    }
};